import 'package:logger/logger.dart';

class DefaultLogFilter extends LogFilter {
  final bool _debug;

  DefaultLogFilter(this._debug);

  @override
  bool shouldLog(LogEvent event) => _debug;
}

class LogHelper {
  late Logger _logger;

  LogHelper._internal();

  static final LogHelper _helper = LogHelper._internal();

  factory LogHelper() => _helper;

  void init({
    LogFilter? filter,
    LogPrinter? printer,
    LogOutput? output,
    Level? level,
  }) {
    _logger =
        Logger(filter: filter, printer: printer, output: output, level: level);
  }

//===Desc:=====================================================================================
  void v(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.v(message, error, stackTrace);
  }

  void d(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.d(message, error, stackTrace);
  }

  void i(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.i(message, error, stackTrace);
  }

  void w(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.w(message, error, stackTrace);
  }

  void e(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.e(message, error, stackTrace);
  }

  void wtf(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    _logger.wtf(message, error, stackTrace);
  }

  //===Desc:=====================================================================================

  void log(dynamic message, [dynamic error, StackTrace? stackTrace]) {
    var level = Logger.level;
    switch (level) {
      case Level.verbose:
        v(message, error, stackTrace);
        break;
      case Level.debug:
        d(message, error, stackTrace);
        break;
      case Level.info:
        i(message, error, stackTrace);
        break;
      case Level.warning:
        w(message, error, stackTrace);
        break;
      case Level.error:
        e(message, error, stackTrace);
        break;
      case Level.wtf:
        wtf(message, error, stackTrace);
        break;
      case Level.nothing:
        e(message, error, stackTrace);
        break;
    }
  }
}
